/**
 * Copyright (c) 2011 ~ 2013 Deepin, Inc.
 *               2011 ~ 2013 jouyouyun
 *
 * Author:      jouyouyun <jouyouwen717@gmail.com>
 * Maintainer:  jouyouyun <jouyouwen717@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 **/

package main

import (
        "dlib/dbus"
        libutils "dlib/utils"
        "fmt"
)

const (
        QT_CONF_FILE    = ".config/Trolltech.conf"
        QT_KEY_GROUP_QT = "Qt"
        QT_KEY_QT_FONT  = "font"
        QT_KEY_QT_STYLE = "style"
)

var utilsObj *libutils.Manager

func testRead() {
        filename := "/home/iwen/" + QT_CONF_FILE

        if ok := utilsObj.IsFileExist(filename); !ok {
                fmt.Printf("'%s' not exist\n", filename)
                return
        }
        fmt.Println("Read Key style")
        v, _ := utilsObj.ReadKeyFromKeyFile(filename, QT_KEY_GROUP_QT, QT_KEY_QT_STYLE, dbus.ObjectPath(""))
        fmt.Println("Value: ", v)

        fmt.Println("Read Key font")
        v, _ = utilsObj.ReadKeyFromKeyFile(filename, QT_KEY_GROUP_QT, QT_KEY_QT_FONT, []byte{})
        fmt.Println("Value: ", v.(string))
}

func testWrite() {
        filename := "/home/iwen/" + QT_CONF_FILE
        if ok := utilsObj.WriteKeyToKeyFile(filename, QT_KEY_GROUP_QT,
                QT_KEY_QT_FONT, "\"DejaVu Sans Mono ,11,-1,5,50,0,0,0,0,0\""); !ok {
                fmt.Println("Write font failed")
        }

        if ok := utilsObj.WriteKeyToKeyFile(filename, QT_KEY_GROUP_QT,
                QT_KEY_QT_STYLE, "GTK+"); !ok {
                fmt.Println("Write style failed")
        }
}

func main() {
        utilsObj = libutils.NewUtils()

        testRead()
        testWrite()
        testRead()
}
